package collect;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class ArrayListDemo {
    public static void main(String[] args) {
		List<Integer> list=new ArrayList<>();
		ArrayList<Integer> list1=new ArrayList<>();
		
		list.add(10);
		list.add(20);
		list.add(30);
		list.add(1, 40);
		for(int i=0;i<list.size();i++)
			System.out.println(list.get(i));
		System.out.println("-----------------------------------");
		
		list1.add(50);
		list1.add(60);
		list1.add(70);
		for(int i=0;i<list1.size();i++)
			System.out.println(list1.get(i));
		System.out.println("-----------------------------------");
			
		list.addAll(list1);
		System.out.println("list1已经加入到list。");
		
        for (Integer i: list) {
        	System.out.println(i);
		}
		System.out.println("-----------------------------------");
		
		Iterator<Integer> it=list.iterator();
		while(it.hasNext()){
			System.out.println(it.next());
		}
		System.out.println("-----------------------------------");
		
		ListIterator<Integer> listit=list.listIterator();
		while(listit.hasNext()){
			System.out.println(listit.next());
		}
		
	    while(listit.hasPrevious()){
	    	System.out.println(listit.previous());
	    }
		
	}
}
